unit ClassTJ3Kml;

interface

uses System.Classes, Contnrs, ClassTJ3BaseTAG, ClassTJ3PlaceMark, ClassTJ3Folder;

CONST
  Cabecalho1 = '<?xml version="1.0" encoding="UTF-8"?>';
  Cabecalho2 = '<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">';

Type
  TJ3Kml = class(TComponent)
    private
      FArq: TStringList;
      FListaFolder: TObjectList;
      FOnAfterSave: TNotifyEvent;
    public
      constructor Create(AOwner: TComponent); override;
      destructor Destroy; override;
      function AddFolder(_nome:String):integer;
      procedure SaveToFile(const _arq: string);
    published
      property OnAfterSave: TNotifyEvent read FOnAfterSave write FOnAfterSave;
      property ListFolder: TObjectList read FListaFolder;
    end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('J3_Tecnologia', [TJ3Kml]);
end;

function TJ3Kml.AddFolder(_nome: String): integer;
begin
  Result := FListaFolder.Add(TJ3KmlFolder.Create(_nome));
end;

constructor TJ3Kml.Create(AOwner: TComponent);
begin
  inherited;
  FArq := TStringList.Create;
  FListaFolder := TObjectList.Create;
end;

destructor TJ3Kml.Destroy;
begin
  FListaFolder.Free;
  FArq.Free;
  inherited;
end;

procedure TJ3Kml.SaveToFile(const _arq: string);
var
 i : Integer;
begin
  FArq.Clear;
  FArq.Add(Cabecalho1);
  FArq.Add(Cabecalho2);
  FArq.Add('<Folder>');
	FArq.Add('<name>Inova Energy</name>');
	FArq.Add('<open>1</open>');

  for i := 0 to FListaFolder.Count-1 do
  begin
    FArq.Add(TJ3KmlBaseTAG(FListaFolder[i]).GetLines);
  end;


  FArq.Add('</Folder>');
  FArq.Add('</kml>');
  FArq.SaveToFile(_arq);

  if Assigned(FOnAfterSave) then
    FOnAfterSave(self);
end;

end.
